package uno.rocc.controller.system;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import uno.rocc.common.core.domain.BaseQueryParam;
import uno.rocc.framework.core.annotation.RoccUnoAuthorize;
import uno.rocc.common.util.Result;
import uno.rocc.framework.core.controller.BaseCURDController;
import uno.rocc.system.domain.dao.SysRole;
import uno.rocc.system.service.SysRoleService;

import java.util.List;

@Tag(name = "系统角色")
@Slf4j
@RestController
@RequestMapping("/sysRole")
@RoccUnoAuthorize("sysRole")
public class SysRoleController extends BaseCURDController<BaseQueryParam, SysRole, SysRole> {

    public SysRoleController(SysRoleService sysRoleService) {
        super(sysRoleService);
    }

    /**
     * 如果重新了查询方法，则需要加上@RoccUnoAuthorize 注解来增加权限验证否则没有权限验证
     *
     * @param param
     * @return
     */
    @RoccUnoAuthorize(":list")
    @Override
    public Result getList(BaseQueryParam param) {
        Page<SysRole> page = startPage();
        service.list(page);
        return Result.success(page);
    }

    @Operation(summary = "新增角色权限")
    @PostMapping("/addPermission/{id}")
    public Result addPermission(@PathVariable("id") Integer id, @RequestBody List<Integer> permissionIds) {
        ((SysRoleService) service).addPermission(id, permissionIds);
        return Result.success();
    }

}
